package cn.swing.learning;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * Desc : TODO
 * ClassName : cn.swing.learning.FirstJDBC
 *
 * @author : 林鹏群
 * @date : 2022/12/24 14:12
 */
public class FirstJDBC {

    public static void main(String[] args) throws Exception {
        //1、加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2、 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/blue?serverTimezone=Asia/Shanghai", "root", "password");
        //3、 创建statement
        PreparedStatement select = connection.prepareStatement("select * from teacher");
        //4、获取结果集
        ResultSet resultSet = select.executeQuery();

        PreparedStatement update = connection.prepareStatement("update teacher set name='xxxx' where id='18'");
        update.executeUpdate();


        PreparedStatement delete = connection.prepareStatement("delete from teacher  where id='19'");
        delete.execute();

        PreparedStatement insert = connection.prepareStatement("insert into teacher  values('11','22','11')");
        insert.execute();




        while (resultSet.next()) {
            System.out.println(resultSet.getString("id")+" "+resultSet.getString("name"));
        }
        //5、关闭
        resultSet.close();
        connection.close();
    }
}
